'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller } = app;
  const isAdmin = app.middlewares.isAdmin();
  const auth = app.middlewares.auth();

  router.get('/iface', controller.home.index);

  router.post('/iface/login', controller.operator.login);
  router.post('/iface/logout', auth, controller.operator.logout);
  // 用户
  router.get('/iface/operators', auth, isAdmin, controller.operator.list);
  router.post('/iface/operator', auth, isAdmin, controller.operator.create);
  router.del('/iface/operator/:id', auth, isAdmin, controller.operator.delete);
  router.post('/iface/operator/:id', auth, isAdmin, controller.operator.update);
  router.get('/iface/operator/:id', auth, isAdmin, controller.operator.get);

  // 上传文件
  router.post('/iface/upload', controller.file.upload);
  // 活动
  router.get('/iface/campaigns', auth, controller.campaign.list);
  router.post('/iface/campaign', auth, controller.campaign.create);
  router.post('/iface/campaign/:id', auth, controller.campaign.update);
  router.post('/iface/campaign/config/:id', auth, controller.campaign.updateConfig);
  router.del('/iface/campaign/:id', auth, controller.campaign.delete);
  router.get('/iface/campaign/:id', auth, controller.campaign.get);
  router.get('/iface/campaigns/search', auth, controller.campaign.search); // 活动名称模糊查询简要信息（开启可选）

  // 奖品
  router.post('/iface/award', auth, controller.award.create);
  router.get('/iface/awards', auth, controller.award.list);
  router.post('/iface/awards/choose', auth, controller.award.chooseList);
  router.post('/iface/award/:id', auth, controller.award.update);
  router.get('/iface/award/:id', auth, controller.award.get);
  router.delete('/iface/award/:id', auth, controller.award.delete);

  // 中奖信息
  router.post('/iface/prizes', auth, controller.prize.list);
  // 历史数据
  router.post('/iface/prizes/history', auth, controller.prize.history);
  // 提交申请（实物,虚拟）
  router.post('/iface/prizes/applyissuing', auth, controller.prize.mark);
  router.post('/iface/smsinfo', auth, controller.sms.list);
  router.post('/iface/dailysms', auth, controller.sms.daily);
  router.post('/iface/sms/template', auth, controller.sms.template);
  router.post('/iface/sendsms', auth, controller.sms.send);

  // APP Banner 投放
  router.get('/iface/banner', auth, controller.banner.getBannerList)
  router.get('/iface/banner/:_id', auth, controller.banner.getBannerById)
  router.post('/iface/banner', auth, controller.banner.createBanner)
  router.post('/iface/banner/:_id', auth, controller.banner.updateBannerById)
  router.del('/iface/banner/:_id', auth, controller.banner.deleteBannerById)
  router.get('/iface/allbanner', auth, controller.banner.getAllBannerList)

  // just for mock
  router.post('/iface/mock/luckdraw', controller.mock.luckdraw);
  router.post('/iface/mock/cash', controller.mock.cash)

  // statistics
  router.post('/iface/statistics/campaign', auth, controller.statistics.campaign);
};
